﻿<?php
$msgtype=0;
    $msqid=0;
    $buf;
    $key;


  if (($key = ftok("kirk.php", 'B')) == -1) {
        echo "błąd ftok\n";
        exit(1);
    }


    if (($msqid = msg_get_queue($key, 0666)) == -1) {
        echo "błąd mngget\n";
        exit(1);
    }
    
    printf("Enter lines of text, ^D to quit:\n");


    $mtype = 1; /* we don't really care in this case */
        $fp=fopen("php://stdin","r");
        while (!feof($fp)){
          $message = stream_get_line($fp, 1024, "\n");
     $len = strlen($message);
     
      if ( !msg_send($msqid, 1/*msg_type*/, $message, 1/*ser*/, TRUE,$err) ){
        
            echo "błąd msgsnd $err\n";
    }
        }
        
    /*if (msgctl(msqid, IPC_RMID, NULL) == -1) {
        perror("msgctl");
        exit(1);
    }*/
    ?>